<template lang="html">
  <section
    class="components-index_list-course_item"
    :class="[{ freeItem: !isEnd && !isQueue && isFree}, { finishedItem: isEnd }, { progressiveItem: !isEnd && isQueue }]"
    @click="$router.push({ path: `/course/${courseDetail.subjectId}` })"
  >
    <div class="activeLayer"></div>
    <div class="course_item-portrait">
      <progressive-img :src="courseDetail.coachAvatar" />
    </div>
    <div class="course_item-content">
      <p class="name">{{courseDetail.subjectName}}</p>
      <p class="coach">{{courseDetail.coachName}}</p>
      <p class="address">{{courseDetail.area}}·{{courseDetail.storeName ? courseDetail.storeName : courseDetail.address}}</p>
      <p class="time">{{isShowDate ? `${this.startDate} ${courseDetail.timeLimit}`:`${courseDetail.timeLimit}`}}</p>
    </div>
    <div class="course_item-tag" v-if="tag">
      {{tag}}
    </div>
    <div class="course_item-action">
      {{action}}
    </div>
  </section>
</template>

<script>
export default {
  props: {
    courseDetail: {
      type: Object,
      required: true
    },
    isShowDate: {
      type: Boolean,
      default: true
    }
  },
  data(){
    return {
      nowTime: 0
    }
  },
  computed: {
    startDate(){
      let ary = this.courseDetail.startDate.split('-')
      return `${ary[1]}月${ary[2]}日`
    },
    action(){
      if(this.isEnd){
        return '已结束'
      } else if(this.isQueue){
        return '取消排队'
      } else if(this.isBuy){
        return '查看预约'
      } else if(this.courseDetail && this.courseDetail.number <= 0){
        return '立即排队'
      } else if(this.isFree){
        return '免费体验'
      } else {
        return `￥${this.courseDetail.currentPrice}`
      }
    },
    tag(){
      if(this.isQueue){
        return '排队中'
      } else if(this.isBuy){
        return ''
      } else if(this.courseDetail && this.courseDetail.number <= 0){
        return '满员'
      } else if(this.courseDetail && this.courseDetail.number < 10){
        return `剩余${this.courseDetail.number}`
      } else {
        return ''
      }
    },
    isQueue(){
      return this.courseDetail && parseInt(this.courseDetail.isQueue) === 1
    },
    isBuy(){
      return this.courseDetail && parseInt(this.courseDetail.isBuy) === 1
    },
    isFree(){
      return this.courseDetail && parseFloat(this.courseDetail.currentPrice, 10) == 0
    },
    isEnd(){
      return this.courseDetail && this.nowTime >= this.courseDetail.endTime*1000
    }
  },
  created(){
    this.nowTime = Date.now()
  }
}
</script>

<style lang="scss" scoped>
@import "../../css/config";
$tag-right: 30px;
$tag-width: 68px;
.components-index_list-course_item{
  position: relative;
  width: 100%;
  height: 189px;
  box-sizing: border-box;
  padding: 0 $course-item-right 0 $course-item-left;
  margin-bottom: 32px;
  border-radius: 21px;
  background-color: #fff;
  &.freeItem{
    background-image: linear-gradient( 0deg, rgb(255,73,10) 0%, rgb(255,80,92) 100%);
    .course_item-content{
      p{
        color: #fff;
      }
      .address{
        color: #fff;//normal color
      }
      .time{
        color: #fff;//normal color
      }
    }
    .course_item-tag{
      color: $common-red;
      background: url('../../assets/image/tag-white.png') no-repeat;
      background-size: cover;
      background-position: top center;
    }
    .course_item-action{
      border: 1Px solid transparent;
    }
    &:active{
      .activeLayer{
        background-color: rgba(255, 255, 255, 0.3);
      }
      .course_item-action{
        color: #e2e2e2;
        background-color: #da6141;
      }
    }
  }
  &.finishedItem{
    background-color: #e2e2e2;
    .course_item-tag{
      display: none;
    }
    .course_item-action{
      background-color: transparent!important;
      color: #575757!important;
      border: 1Px solid transparent;
    }
  }
  &.progressiveItem{
    .course_item-action{
      background-color: transparent;
      color: #575757;
      border: 1Px solid #575757;
    }
  }
  .activeLayer{
    position: absolute;
    display: block;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 21px;
    transform: rotate(0);
    overflow: hidden;
    background-color: transparent;
    // background-color: rgba(255, 255, 255, 0.3);
  }
  &:active{
    background-color: #e2e2e2;
    .course_item-action{
      color: #e2e2e2;
      background-color: #ff505f;
    }
  }
  .course_item-portrait{
    position: absolute;
    left: 30px;
    top: 50%;
    width: 115px;
    height: 115px;
    border-radius: 100%;
    border: 1Px solid #ff591c;
    transform: rotate(0) translateY(-50%);
    overflow: hidden;
  }
  .course_item-content{
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 0;
    box-sizing: border-box;
    p{
      display: block;
      width: 100%;
      line-height: 1.2;
      color: #000;
      @include text-overflow;
    }
    .name{
      font-size: 33px;
    }
    .coach{
      font-size: 25px;
      color: #000;
    }
    .address{
      color: #575757;//normal color
      font-size: 21px;
    }
    .time{
      color: #575757;//normal color
      font-size: 25px;
    }
  }
  .course_item-tag{
    position: absolute;
    top: 0;
    right: $tag-right;
    width: $tag-width;
    height: 55px;
    line-height: 48px;
    text-align: center;
    font-size: 21px;
    color: #fff;
    // color: $common-red;
    font-weight: 100;
    background: url('../../assets/image/tag-red.png') no-repeat;
    // background: url('../../assets/image/tag-white.png') no-repeat;
    background-size: cover;
    background-position: top center;
  }
  .course_item-action{
    position: absolute;
    top: 50%;
    transform: translateY(-45%);
    right: $tag-right;
    width: 135px;
    height: 60px;
    line-height: 60px;
    text-align: center;
    border-radius: 10px;
    border: 1Px solid $common-red;
    // border: 1Px solid transparent;
    background-color: #fff;
    color: $common-red;
    font-size: 25px;
    @include text-overflow;
  }
}
</style>
